package com.joeljhou.project.core.listener;

import com.joeljhou.project.core.data.DataListener;
import com.joeljhou.project.form.Component;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ClearListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        // 处理按钮点击事件
        Component component = Component.getInstance();

        //数据面板
        JTextPane dataArea = component.getDataArea();
        dataArea.setText("");

        //清空数据
        DataListener.listData.clear();

        //清空表格数据
        JTable table = component.getStatisticsTable();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        // 创建一个表格模型，并设置列名和数据
        model.setValueAt("", 0, 1);  //修改第1行第2列的数据
        model.setValueAt("", 1, 1);
        model.setValueAt("", 2, 1);
        model.setValueAt("", 3, 1);
        model.setValueAt("", 4, 1);
        model.setValueAt("", 5, 1);

        component.printLog("数据清除成功", Color.BLACK);
    }
}
